//
//  DengLuViewController.m
//  个人项目(豆瓣元旦作业)
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 guoguo. All rights reserved.
//

#import "DengLuViewController.h"
#import "RegisterViewController.h"
#import "HGdlDataBase.h"

@interface DengLuViewController ()


@property (nonatomic, retain) UITextField *text1;
@property (nonatomic, retain) UITextField *text2;
@end

@implementation DengLuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"用户登陆";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 100, 50)];
    label.text = @"用户名:";
    label.font = [UIFont systemFontOfSize:21];
    [self.view addSubview:label];
    
    
    UILabel *label2 = [[UILabel alloc] init];
    label2.frame = CGRectMake(40, 150, 100, 50);
    label2.text = @"密码:";
    label2.font = [UIFont systemFontOfSize:21];
    
    [self.view addSubview:label2];
    
    
    

    
    self.text1 = [[UITextField alloc] initWithFrame:CGRectMake(130, 110, 200, 40)];
    _text1.placeholder = @"请输入用户名";
    _text1.clearButtonMode = YES;
    _text1.clearsOnBeginEditing = YES;
    _text1.borderStyle = UITextBorderStyleRoundedRect;
   
    [self.view addSubview:_text1];
    
    
    self.text2 = [[UITextField alloc] initWithFrame:CGRectMake(130, 160, 200, 40)];
    _text2.placeholder = @"请输入密码";
    _text2.clearsOnBeginEditing = YES;
    _text2.secureTextEntry = YES;
    _text2.clearButtonMode = YES;
    _text2.borderStyle = UITextBorderStyleRoundedRect;
   
    [self.view addSubview:_text2];
    
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(50, 220, 125, 50);
    button1.backgroundColor = [UIColor cyanColor];
    button1.layer.cornerRadius = 10;
    button1.layer.masksToBounds = YES;
    
    button1.layer.borderWidth = 2;
    button1.layer.borderColor = [UIColor whiteColor].CGColor;
    [button1 setTitle:@"登陆" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    [self.view addSubview:button1];
    
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    
    button2.frame = CGRectMake(200, 220, 125, 50);
    button2.backgroundColor = [UIColor orangeColor];
    button2.layer.cornerRadius = 10;
    button2.layer.masksToBounds = YES;
    
    button2.layer.borderColor = [UIColor whiteColor].CGColor;
    button2.layer.borderWidth = 2;
    
    [button2 setTitle:@"注册" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button2];
    
    
    
    
}
//登陆按钮
- (void)button1Action:(UIButton *)button{
    
    
    NSMutableArray *arr = [[HGdlDataBase sharedHGdlDataBase] selectData];
    
    NSMutableArray *strM = [NSMutableArray array];
    
    for (DengLuDataBaseModel *model in arr) {
        
        NSString *str = model.textFieldM;
        
        [strM addObject:str];
        }
   
    if ([strM containsObject:_text1.text]) {
        
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else{
        
        UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示 " message:@"未注册" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"注册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
           
            RegisterViewController *re = [[RegisterViewController alloc] init];
            [self.navigationController pushViewController:re animated:YES
             ];
        }];
        
        
        [alert1 addAction:action];
        [alert1 addAction:action1];
        
        [self presentViewController:alert1 animated:YES completion:^{
            
        }];
        
    }
    
    
    
    
}


//注册
//button的点击方法
- (void)button2Action:(UIButton *)button{
    
    RegisterViewController *reg = [[RegisterViewController alloc] init];
    
    [self.navigationController pushViewController:reg animated:YES];
    
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
